package com.zys.background.common.annotation;


import com.zys.background.common.regex.RegexPattern;
import com.zys.background.common.validator.PhoneValidator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

/**
 * @author zys
 * @since 2022-11-11
 */
@Documented
@Repeatable(Phone.List.class)
@Constraint(validatedBy = PhoneValidator.class)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Phone {
  String message() default "手机号码格式错误";

  Class<?>[] groups() default {};

  Class<? extends Payload>[] payload() default {};

  String regexp() default RegexPattern.PHONE_REGEX;

  @Documented
  @Retention(RetentionPolicy.RUNTIME)
  @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.TYPE_USE})
  @interface List {
    Phone[] value();
  }
}